package com.google.android.material.behavior;

import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior;
import androidx.core.view.ViewCompat;
import o.jf;
import o.jf.e;

public class SwipeDismissBehavior<V extends View> extends Behavior<V> {
    private boolean ʻ;
    private final e ʼ = new e(this) {
        final /* synthetic */ SwipeDismissBehavior ˋ;
        private int ˏ = -1;
        private int ॱ;

        {
            this.ˋ = r2;
        }

        public boolean ˏ(View view, int i) {
            return this.ˏ == -1 && this.ˋ.ˋ(view);
        }

        public void ˊ(View view, int i) {
            this.ˏ = i;
            this.ॱ = view.getLeft();
            ViewParent parent = view.getParent();
            if (parent != null) {
                parent.requestDisallowInterceptTouchEvent(true);
            }
        }

        public void ˏ(int i) {
            if (this.ˋ.ˎ != null) {
                this.ˋ.ˎ.ॱ(i);
            }
        }

        public void ˎ(View view, float f, float f2) {
            this.ˏ = -1;
            int width = view.getWidth();
            boolean z = false;
            if (ˏ(view, f)) {
                width = view.getLeft() < this.ॱ ? this.ॱ - width : this.ॱ + width;
                z = true;
            } else {
                width = this.ॱ;
            }
            if (this.ˋ.ˊ.ˋ(width, view.getTop())) {
                ViewCompat.ˏ(view, new b(this.ˋ, view, z));
            } else if (z && this.ˋ.ˎ != null) {
                this.ˋ.ˎ.ˎ(view);
            }
        }

        private boolean ˏ(View view, float f) {
            if (f != 0.0f) {
                boolean z = ViewCompat.ʼ(view) == 1;
                if (this.ˋ.ˋ == 2) {
                    return true;
                }
                if (this.ˋ.ˋ == 0) {
                    if (z) {
                        if (f >= 0.0f) {
                            return false;
                        }
                        return true;
                    } else if (f <= 0.0f) {
                        return false;
                    } else {
                        return true;
                    }
                } else if (this.ˋ.ˋ != 1) {
                    return false;
                } else {
                    if (z) {
                        if (f <= 0.0f) {
                            return false;
                        }
                        return true;
                    } else if (f >= 0.0f) {
                        return false;
                    } else {
                        return true;
                    }
                }
            }
            if (Math.abs(view.getLeft() - this.ॱ) < Math.round(((float) view.getWidth()) * this.ˋ.ˏ)) {
                return false;
            }
            return true;
        }

        public int ˊ(View view) {
            return view.getWidth();
        }

        public int ˎ(View view, int i, int i2) {
            int width;
            int i3;
            Object obj = ViewCompat.ʼ(view) == 1 ? 1 : null;
            if (this.ˋ.ˋ == 0) {
                if (obj != null) {
                    width = this.ॱ - view.getWidth();
                    i3 = this.ॱ;
                } else {
                    width = this.ॱ;
                    i3 = this.ॱ + view.getWidth();
                }
            } else if (this.ˋ.ˋ != 1) {
                width = this.ॱ - view.getWidth();
                i3 = this.ॱ + view.getWidth();
            } else if (obj != null) {
                width = this.ॱ;
                i3 = this.ॱ + view.getWidth();
            } else {
                width = this.ॱ - view.getWidth();
                i3 = this.ॱ;
            }
            return SwipeDismissBehavior.ˎ(width, i, i3);
        }

        public int ˋ(View view, int i, int i2) {
            return view.getTop();
        }

        public void ॱ(View view, int i, int i2, int i3, int i4) {
            float width = ((float) this.ॱ) + (((float) view.getWidth()) * this.ˋ.ॱ);
            float width2 = ((float) this.ॱ) + (((float) view.getWidth()) * this.ˋ.ᐝ);
            if (((float) i) <= width) {
                view.setAlpha(1.0f);
            } else if (((float) i) >= width2) {
                view.setAlpha(0.0f);
            } else {
                view.setAlpha(SwipeDismissBehavior.ॱ(0.0f, 1.0f - SwipeDismissBehavior.ˋ(width, width2, (float) i), 1.0f));
            }
        }
    };
    private float ʽ = 0.0f;
    jf ˊ;
    int ˋ = 2;
    d ˎ;
    float ˏ = 0.5f;
    float ॱ = 0.0f;
    private boolean ॱॱ;
    float ᐝ = 0.5f;

    class b implements Runnable {
        private final View ˋ;
        private final boolean ˎ;
        final /* synthetic */ SwipeDismissBehavior ॱ;

        b(SwipeDismissBehavior swipeDismissBehavior, View view, boolean z) {
            this.ॱ = swipeDismissBehavior;
            this.ˋ = view;
            this.ˎ = z;
        }

        public void run() {
            if (this.ॱ.ˊ != null && this.ॱ.ˊ.ˋ(true)) {
                ViewCompat.ˏ(this.ˋ, this);
            } else if (this.ˎ && this.ॱ.ˎ != null) {
                this.ॱ.ˎ.ˎ(this.ˋ);
            }
        }
    }

    public interface d {
        void ˎ(View view);

        void ॱ(int i);
    }

    public void ˎ(d dVar) {
        this.ˎ = dVar;
    }

    public void ˏ(int i) {
        this.ˋ = i;
    }

    public void ˋ(float f) {
        this.ॱ = ॱ(0.0f, f, 1.0f);
    }

    public void ˏ(float f) {
        this.ᐝ = ॱ(0.0f, f, 1.0f);
    }

    public boolean ˎ(CoordinatorLayout coordinatorLayout, V v, MotionEvent motionEvent) {
        boolean z = this.ʻ;
        switch (motionEvent.getActionMasked()) {
            case 0:
                this.ʻ = coordinatorLayout.ˋ(v, (int) motionEvent.getX(), (int) motionEvent.getY());
                z = this.ʻ;
                break;
            case 1:
            case 3:
                this.ʻ = false;
                break;
        }
        if (!z) {
            return false;
        }
        ˎ((ViewGroup) coordinatorLayout);
        return this.ˊ.ˏ(motionEvent);
    }

    public boolean ॱ(CoordinatorLayout coordinatorLayout, V v, MotionEvent motionEvent) {
        if (this.ˊ == null) {
            return false;
        }
        this.ˊ.ˋ(motionEvent);
        return true;
    }

    public boolean ˋ(@NonNull View view) {
        return true;
    }

    private void ˎ(ViewGroup viewGroup) {
        if (this.ˊ == null) {
            jf ˊ;
            if (this.ॱॱ) {
                ˊ = jf.ˊ(viewGroup, this.ʽ, this.ʼ);
            } else {
                ˊ = jf.ˋ(viewGroup, this.ʼ);
            }
            this.ˊ = ˊ;
        }
    }

    static float ॱ(float f, float f2, float f3) {
        return Math.min(Math.max(f, f2), f3);
    }

    static int ˎ(int i, int i2, int i3) {
        return Math.min(Math.max(i, i2), i3);
    }

    static float ˋ(float f, float f2, float f3) {
        return (f3 - f) / (f2 - f);
    }
}
